package com.bjx.common.tenant.config;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.bjx.common.security.util.LoginUtil;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
@MapperScan("com.bjx")
public class BjxTenantLineHandler implements TenantLineHandler {
    private static final List<String> IGNORE_TABLE = ListUtil.of("sys_tenant,sys_menu");

    /** 
     * 租户ID表达式
      
     * @return: net.sf.jsqlparser.expression.Expression 
     * @author liushuai
     */ 
    @Override
    public Expression getTenantId() {
        return new StringValue(LoginUtil.getTenantId());
    }

    /**
     * 根据表名判断是否忽略拼接多租户条件
     * @param tableName:  当前表明
     * @return: boolean true标识忽略  false标识不忽略
     * @author liushuai
     */
    @Override
    public boolean ignoreTable(String tableName) {
        return IGNORE_TABLE.contains(tableName);
    }
}
